package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.gemme.gemme.R;

public class PersonOrDanweiView extends RelativeLayout {
    private Context context;
    private OnChangeLIstener onChangeLIstener;

    public PersonOrDanweiView(Context context) {
        this(context,null);
    }

    public PersonOrDanweiView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public PersonOrDanweiView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    RoundCheckBox cb_person;
    RoundCheckBox cb_danwei;
    boolean isPerson = true;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.person_danwei_view,this);
         cb_person= findViewById(R.id.cb_person);
         cb_danwei= findViewById(R.id.cb_danwei);

        cb_person.setChecked(isPerson);
        cb_danwei.setChecked(!isPerson);
        controlPersonOrdanwei();
    }

    private void controlPersonOrdanwei() {
        cb_person.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_person.isChecked();
                isPerson = checked;
                setIsPerson();
                onChangeLIstener.onChangeLIstener();
            }
        });
        cb_danwei.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_person.isChecked();
                isPerson = !checked;
                setIsPerson();
                onChangeLIstener.onChangeLIstener();
            }
        });
    }

    private void setIsPerson() {
        cb_person.setChecked(isPerson);
        cb_danwei.setChecked(!isPerson);

    }

    public void setstate(boolean isPerson){
        this.isPerson = isPerson;
        setIsPerson();
    }

    public boolean getIsPerson(){
        return isPerson;
    }

    public void setOnChangeLIstener(OnChangeLIstener onChangeLIstener){

        this.onChangeLIstener = onChangeLIstener;
    }
}
